package org.itworks.biodev.gui.panels;

import java.util.*;

import org.itworks.biodev.model.*;
import org.itworks.helpers.*;

public class OrdersPanelModel extends Observable {

	private Vector<Order> orders;
	private Vector<ProductOrder> products;
	
	public void setOrdersList(Vector<Order> orders) {
		this.setChanged();
		this.orders = orders;
		this.notifyObservers(new MVCNotification(OrdersPanelView.FILL_ORDERS_TABLE, orders));
		this.clearChanged();
	}
	
	public void setProductsList(Order order) {
		try {
			this.setChanged();
			this.notifyObservers(new MVCNotification(OrdersPanelView.FILL_ORDER_ID_LABEL, "Commande "+order.getId().toString()));
			this.clearChanged();
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			this.setChanged();
			this.products = ProductOrderTable.getInstance().findProductByOrder(order);
			this.notifyObservers(new MVCNotification(OrdersPanelView.FILL_ORDER_DETAILS_TABLE, products));
			this.clearChanged();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public Vector<Order> getOrders() {
		return orders;
	}
	
	public Vector<ProductOrder> getProducts() {
		return products;
	}
}
